﻿Imports System.Data.SqlClient

Public Class frmDataLock

    Sub FillLockDate()
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim cmd As New SqlCommand("Select LockDate From LockDate", cnn1)

            cnn1.Open()
            Me.lblLockDate.Text = CDate(cmd.ExecuteScalar).ToString("dd-MMM-yyyy")
            cnn1.Close()

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            MsgBox(ex.ToString)
            If cnn1.State = ConnectionState.Open Then
                cnn1.Close()
            End If
        End Try
    End Sub

    Private Sub btnGClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGClose.Click
        Me.Close()
    End Sub

    Private Sub btnGSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGSave.Click
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim cmd As New SqlCommand("Update LockDate Set LockDate=N'" & Me.DateTimePicker1.Value.ToShortDateString & " 23:59:59'", cnn)

            cnn.Open()
            cmd.ExecuteNonQuery()
            cnn.Close()

            FillLockDate()

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub frmLockData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillLockDate()
    End Sub
End Class